<?php
/**
 * RUBIK IT Solution & Development ltd.
 *
 * PROJECT		: Rubik Ultimate
 * @version 	: 1.1
 * COPYRIGHT	: 2008
 * ------------------------------------------------------
 * 
 * [GENERAL INFO OF THIS FILE] 
 *
 * @author			hoadn <hoadn@rubik.com.vn>
 * @package		 	core.html.filedInfo
 *
 * Created on	:Sep 19, 2008
 */

// no direct access
defined ( '_FW_EXEC' ) or die ( 'Restricted access' );

RCoreImporter::cls('html.fieldInfo.BasicFileHtmlFieldInfo');

class FlashFileHtmlFieldInfo extends BasicFileHtmlFieldInfo {
	
	var $_thumbSize;
	var $_largeSize;
	
	/**
	 * Constructor
	 *
	 * @param string $basicName
	 */
	function __construct($basicName, $linkRule = null) {
		parent::__construct($basicName, $linkRule);
		$this->_thumbSize = array('width'=>100, 'height'=>50);
		$this->_largeSize = array('width'=>null, 'height'=>null);
	}
	
	/**
	 * Set the thumbnail size
	 *
	 * @param int $width
	 * @param int $height
	 */
	function setThumbSize($width, $height) {
		 $this->_thumbSize = array('width'=>$width, 'height'=>$height);
	}

	/**
	 * Set the large size
	 *
	 * @param int $width
	 * @param int $height
	 */
	function setLargeSize($width, $height) {
		 $this->_largeSize = array('width'=>$width, 'height'=>$height);
	}
	
	/**
	 * Function for geting the html for previewing data
	 *
	 * @return string
	 */
	function buildHtmlPreviewData($extAttributes = '', $key=null, $dataType ='S') {
		$fileURL = $this->getDownloadableLink();
		
		if ($fileURL == '#') {
			$noFileMsg = SysLanguage::_('No file');
			return '<div style="text-align:center;">'.$noFileMsg.'</div>';
		}
		
		$width1 = $this->_thumbSize['width'];
		$height = $this->_thumbSize['height'];
		$html = RHtmlHelper::createFlashObject($fileURL, $width1, $height);

		$css = "
		.flash_preview div.view {
			left: {$width1}px;
		}
		";
		SysResponse::addStyleSheetContent($css);
		
		
		$width = $this->_largeSize['width'];
		$height = $this->_largeSize['height'];
		$html1 = RHtmlHelper::createFlashObject($fileURL, $width, $height);
		
		$html = '<div class="flash_preview" style="width: '.$width1.'px;"><div class="preview">'.$html.'</div><div class="view">'.$html1.'</div></div>';
		return $html;
	}
	
	/**
	 * Function for geting the html for inputing data
	 *
	 * @abstract 
	 * @return string
	 */
	function getHtmlInputData($dataType = '', $extAttribute = '') {
		$html = parent::getHtmlInputData($dataType, $extAttribute);
		$removeName = "ctrl_rm_".$this->_fieldName;
		$removeText = SysLanguage::_('Remove this field');
		$preview = $this->buildHtmlPreviewData($extAttribute);
		$html = "   <div>{$html}</div>
					<div style=\"float:left; padding-right: 10px;\">
						<input type=\"checkbox\" value=\"1\" name=\"{$removeName}\" id=\"{$removeName}\" style=\"width: 30px;\"/>
						<label for=\"{$removeName}\">{$removeText}</label>
					</div>
					<div style=\"float:right\">{$preview}</div>
					<div style=\"clear:both;\" />";
		return $html;
	}
	
}
?>